package com.example.peibei.ui.adapter;

import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dingtao.common.bean.Order;
import com.dingtao.common.util.GlideUtils;
import com.example.peibei.R;

import java.util.List;

public class HomeOrderListAdapter extends BaseQuickAdapter<Order.RecordsDTO, BaseViewHolder> {

    public HomeOrderListAdapter(@Nullable List<Order.RecordsDTO> data) {
        super(R.layout.item_order_list_two, data);
    }
    public HomeOrderListAdapter() {
        super(R.layout.item_order_list_two);
    }

    @Override
    protected void convert(BaseViewHolder helper, Order.RecordsDTO item) {
        ImageView head = helper.getView(R.id.iv_head);
        String img = item.getImgs().get(0);
        if (img.startsWith("http")) {
            GlideUtils.loadImg(getContext(), img, 20, head);
        } else {
            GlideUtils.loadImg(getContext(), "https://resource.quqdan.com/" + img, 20, head);
        }
        String nickName = item.getNickName();
        if (nickName != null){
            if (nickName.length() > 5){
                nickName = nickName.substring(0,5)+"...";
            }
        }
        helper.setText(R.id.tv_name, nickName).setText(R.id.tv_address, item.getArea())
                .setText(R.id.tv_dec, item.getOtherDesc()).setText(R.id.tv_cate, item.getCategory())
                .setText(R.id.tv_online, item.getOnline());
        if (item.getPrice().contains(".")) {
            String[] split = item.getPrice().split("\\.");
            helper.setText(R.id.tv_price, split[0]);
        } else {
            helper.setText(R.id.tv_price, item.getPrice());
        }

        helper.setGone(R.id.iv_cert,!item.isIdBoolean());
        helper.setGone(R.id.iv_vip,!item.isVip());

        if ("0".equals(item.getUnit())){
            helper.setText(R.id.tv_unit,"/小时");
        }else if ("1".equals(item.getUnit())){
            helper.setText(R.id.tv_unit,"/天");
        }else if("-1".equals(item.getUnit())){
            helper.setText(R.id.tv_unit,"一口价");
        }
    }
}
